package com.my.study.dto;

import com.my.study.entity.MyUserEntity;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.core.user.OAuth2User;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author Carlos
 * @version 1.0.0
 * @date 2022/1/7 8:31
 */
@Data
public class JwtUserDto implements UserDetails, OAuth2User {
    private static final long serialVersionUID = 6358221977885208880L;

    private MyUserEntity myUserEntity;

    private Collection<GrantedAuthority> authorities;
    
    private Map<String, Object> attributes;

    public JwtUserDto(MyUserEntity myUserEntity) {
        this.myUserEntity = myUserEntity;
    }


    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    /** 解密后的密码 */
    @Override
    public String getPassword() {
        return myUserEntity.getPassword();
    }

    /** 用户名 */
    @Override
    public String getUsername() {
        return myUserEntity.getUserName();
    }

    /** 是否过期 */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /** 是否锁定 */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /** 凭证是否过期 */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public String getName() {
        return myUserEntity.getUserName();
    }
}
